<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>组件生命周期（旧）</title>
</head>
<body>
    <div id="app"></div>

    <script type="text/javascript" src="../js/react.development.js"></script>
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <script type="text/javascript" src="../js/babel.min.js"></script>

    <script type="text/babel">
        class Life extends React.Component {
            // 自定义状态
            state = {number:0}

            // 自定义事件
            death = () => {
                // 卸载组件
                ReactDOM.unmountComponentAtNode(document.querySelector('#app'))
            }
            add = ()=>{
                let {number} = this.state
                this.setState({number:number+1})
            }
            updata = ()=>{
                this.forceUpdate()
            }

            // 组件将被挂载
            componentWillMount() {
                console.log('componentwillMount');
            }
            // 组件将被卸载
            componentWillUnmount() {
                console.log('componentWillUnmount');
            }
            // 组件被挂载
            componentDidMount() {
                console.log('componentDidMount');
            }
            // 组件是否要更新
            shouldComponentUpdate() {
                console.log('shouldComponentUpdata');
                return true
            }
            // 组件将要更新
            componentWillUpdate() {
                console.log('componentWillUpdate');
            }
            // 组件更新完毕
            componentDidUpdate() {
                console.log('componentDidUpdate');
            }
            
            render() {
                console.log('render');
                return (
                    <div id="">
                        <h2>{this.state.number}</h2>
                        <button onClick={this.death}>卸载组件</button>
                        <button onClick={this.add}>加一</button>
                        <button onClick={this.updata}>强制更新</button>
                    </div>
                )
            }
        }

        ReactDOM.render(<Life/>,document.querySelector("#app"))

    </script>
</body>
</html>